From : Peter Liebetrau (zippo@edina.xnc.com)
Subject : Getting running program's name
There  is  a  command  in  the  doslibrary  since OS2.0 to get the
programname.  Syntax is ...

GetProgramName_ buffer.l,length.l

where buffer is the pointer to an initialized string and length is
the  maxlength  of  th  name.   with  a  length of 256 bytes u are
allways sure, I think.

Example:

pname$  = String$(Chr$(0),256)
GetProgramName_ &pname$,256
pname$  = Peek$(&pname$)
NPrint pname$

In the 3rd line u can also use a 
pname$  = StripTrail$(pname$,0)

This is more sure, if someone had hacked a 0-char in the progname.